/**
 * @Copyright (c) 2017, 家校通信息科技有限公司 All Rights Reserved.
 */
package com.school.teaching.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.school.teaching.dto.ResultDTO;
import com.school.teaching.dto.TrackerDTO;
import com.school.teaching.enums.StatusEnum;
import com.school.teaching.exception.ServiceException;
import com.school.teaching.service.TrackerService;

/**
 * @Description 跟踪器
 * @Author hesheng
 * @Date 2017年3月10日 下午3:25:12
 */
@RestController
@RequestMapping("/tracker")
public class TrackerController {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(TrackerController.class);

	@Autowired
	private TrackerService trackerService;
	
	/**
	 * 注册
	 * @param register
	 * @return
	 */
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public ResultDTO register(@RequestBody TrackerDTO tracker) {
		LOGGER.info("注册信息：{}", tracker);
		ResultDTO result = new ResultDTO();
		try {
			trackerService.register(tracker);
			result.setStatus(StatusEnum.REGISTER_SUCCESS.getValue());
			result.setMessage(StatusEnum.REGISTER_SUCCESS.getText());
			LOGGER.info(result.getMessage());
		} catch (Exception e) {
			result.setStatus(StatusEnum.REGISTER_FAIL.getValue());
			if (e instanceof ServiceException) {
				LOGGER.error(e.getMessage());
				result.setMessage(e.getMessage());
			} else {
				LOGGER.error(StatusEnum.ERROR.getText(), e);
				result.setMessage(StatusEnum.ERROR.getText());
			}
		}
		LOGGER.info("返回信息：{}", result);
		return result;
	}
}
